
load('summary_data/figs7_8_A12_A13_A14.rda')
source('utils.R')

c3 = render_basic(c3) +
  scale_y_continuous(labels = scales::label_percent(big.mark = ','),
                     breaks = c(seq(-1, 2, .5), seq(3, 10, 1))) +
  scale_shape_manual(name = 'Ethnicity',
                     values = c(20, 4),
                     labels = c('B', 'W')) +
  labs(
    x = element_blank(),
    y = '% Change from 2012 Copartisan',
    color = element_blank(),
    subtitle = 'Ethnicity (Black, White)'
  )

c5 = render_basic(c5) +
  scale_y_continuous(labels = scales::label_percent(big.mark = ','),
                     breaks = c(seq(-1, 2, .5), seq(3, 10, 1))) +
  scale_shape_manual(name = 'Ethnicity',
                     values = c(20, 4),
                     labels = c('A', 'W')) +
  labs(
    x = element_blank(),
    y = '% Change from 2012 Copartisan',
    color = element_blank(),
    subtitle = 'Ethnicity (Asian, White)'
  )

c7 = render_basic(c8) +
  scale_y_continuous(labels = scales::label_percent(big.mark = ','),
                     breaks = c(seq(-1, 2, .5), seq(3, 10, 1))) +
  scale_shape_manual(name = 'Ethnicity',
                     values = c(20, 4),
                     labels = c('H', 'W')) +
  labs(
    x = element_blank(),
    y = '% Change from 2012 Copartisan',
    color = element_blank(),
    subtitle = 'Ethnicity (Hispanic, White)'
  )

legend = c3 + guides(shape = 'none') + theme(legend.position = 'bottom')
legend = get_legend_35(legend)

c3 = c3 +
  scale_y_continuous(labels = scales::label_percent(),
                     breaks = c(seq(-1, 2, .5), seq(3, 8, 1))) +
  expand_limits(y = c(-1, 8)) +
  guides(color = 'none', shape = guide_legend(nrow = 1)) +
  scale_shape_manual(
    name = element_blank(),
    values = c(20, 4),
    labels = c('Black', 'White')
  ) +
  labs(subtitle = element_blank(), shape = element_blank()) +
  theme(plot.margin = margin(t = -0.5, 1, 1, 1))

c5 = c5 +
  scale_y_continuous(labels = scales::label_percent(),
                     breaks = c(seq(-1, 2, .5), seq(3, 8, 1))) +
  expand_limits(y = c(-1, 8)) +
  guides(color = 'none', shape = guide_legend(nrow = 1)) +
  scale_shape_manual(
    name = element_blank(),
    values = c(20, 4),
    labels = c('Asian', 'White')
  ) +
  labs(subtitle = element_blank(),
       y = element_blank(),
       shape = element_blank()) +
  theme(plot.margin = margin(t = -0.5, 1, 1, 1))

c7 = c7 +
  scale_y_continuous(labels = scales::label_percent(),
                     breaks = c(seq(-1, 2, .5), seq(3, 8, 1))) +
  expand_limits(y = c(-1, 8)) +
  guides(color = 'none', shape = guide_legend(nrow = 1)) +
  scale_shape_manual(
    name = element_blank(),
    values = c(20, 4),
    labels = c('Hispanic', 'White')
  ) +
  labs(subtitle = element_blank(),
       y = element_blank(),
       shape = element_blank()) +
  theme(plot.margin = margin(t = -0.5, 1, 1, 1))

plot = plot_grid(c3 + guides(shape = 'none'),
                 c5 + guides(shape = 'none'),
                 c7 + guides(shape = 'none'),
                 nrow = 1)

plot = plot_grid(plot, legend, rel_heights = c(9, .35), nrow = 2)

shapes = plot_grid(get_legend_35(c3),
                   get_legend_35(c5),
                   get_legend_35(c7),
                   nrow = 1)

plot = plot_grid(shapes, plot, rel_heights = c(.5, 9), nrow = 2)

ggsave(filename = 'figures/figA14.pdf', plot = plot, width = 8, height = 5, units = 'in')
